﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:params="http://schemas.codeplex.com/elysium/params"
                    xmlns:controls="clr-namespace:Framework.UI.Controls">
    <ResourceDictionary.MergedDictionaries>
        <controls:SharedResourceDictionary Source="/Framework.UI;component/Themes/WPF/Base/Converter.xaml"/>
        <controls:SharedResourceDictionary Source="/Framework.UI;component/Themes/WPF/Base/Brush.xaml"/>
        <controls:SharedResourceDictionary Source="/Framework.UI;component/Themes/WPF/Base/FocusVisualStyle.xaml"/>
        <controls:SharedResourceDictionary Source="/Framework.UI;component/Themes/WPF/Base/Validation.xaml"/>
        <controls:SharedResourceDictionary Source="/Framework.UI;component/Themes/WPF/Controls/ScrollBar.xaml"/>
        <controls:SharedResourceDictionary Source="/Framework.UI;component/Themes/ElysiumExtra/BorderFix.xaml"/>
    </ResourceDictionary.MergedDictionaries>

    <Style x:Key="ComboBoxTextBox" TargetType="{x:Type TextBox}" >
        <Setter Property="TextOptions.TextFormattingMode" Value="Display" />
        <Setter Property="TextOptions.TextRenderingMode" Value="ClearType" />
        <Setter Property="RenderOptions.ClearTypeHint" Value="Enabled" />
        <Setter Property="TextBoxBase.CaretBrush" Value="{StaticResource ForegroundBrush}" />
        <Setter Property="TextBoxBase.SelectionBrush" Value="{StaticResource MiddleLightBrush}" />
        <Setter Property="FocusVisualStyle" Value="{x:Null}" />
        <Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst" />
        <Setter Property="Stylus.IsFlicksEnabled" Value="False" />
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type TextBox}">
                    <Border Background="{StaticResource TransparentBrush}" 
                            BorderThickness="0" 
                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
                        <ScrollViewer x:Name="PART_ContentHost" Foreground="{TemplateBinding Foreground}" Control.FontFamily="{TemplateBinding Control.FontFamily}" FontSize="{TemplateBinding FontSize}" FontStretch="{TemplateBinding FontStretch}" FontStyle="{TemplateBinding FontStyle}" FontWeight="{TemplateBinding FontWeight}" TextOptions.TextFormattingMode="{TemplateBinding TextOptions.TextFormattingMode}" TextOptions.TextRenderingMode="{TemplateBinding TextOptions.TextRenderingMode}" RenderOptions.ClearTypeHint="{TemplateBinding RenderOptions.ClearTypeHint}" Margin="{TemplateBinding Padding}" Background="{x:Null}" />
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <DataTrigger DataTrigger.Binding="{Binding RelativeSource={RelativeSource Self},Path=FontSize,Mode=OneWay,Converter={StaticResource IsGreaterThanConverter},ConverterParameter=18}">
                <Setter Property="TextOptions.TextFormattingMode" Value="Ideal" />
            </DataTrigger>
        </Style.Triggers>
    </Style>

    <Style x:Key="ComboBoxToggleButton" TargetType="{x:Type ToggleButton}" >
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ToggleButton}">
                    <Border Background="{StaticResource TransparentBrush}" 
                            BorderThickness="0" 
                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
                        <Polygon Name="ArrowGlyph" Fill="{StaticResource MiddleLightBrush}" StrokeThickness="0" Stretch="Uniform" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="{Binding RelativeSource={RelativeSource AncestorType={x:Type ComboBox}},Path=(params:ComboBox.ArrowMargin),Mode=OneWay}" Width="{Binding RelativeSource={RelativeSource AncestorType={x:Type ComboBox}},Path=(params:ComboBox.ArrowSize),Mode=OneWay}" Height="{Binding RelativeSource={RelativeSource AncestorType={x:Type ComboBox}},Path=(params:ComboBox.ArrowSize),Mode=OneWay}">
                            <Polygon.Points>
                                <PointCollection>
                                    <Point Point.X="0" Point.Y="0" />
                                    <Point Point.X="3" Point.Y="4" />
                                    <Point Point.X="6" Point.Y="0" />
                                </PointCollection>
                            </Polygon.Points>
                        </Polygon>
                    </Border>
                    <ControlTemplate.Triggers>
                        <DataTrigger DataTrigger.Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type ComboBox}},Path=IsDropDownOpen,Mode=OneWay}">
                            <Setter TargetName="ArrowGlyph" Value="{StaticResource AccentBrush}" Property="Fill" />
                        </DataTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="{x:Type ComboBox}" TargetType="{x:Type ComboBox}" >
        <Setter Property="Background" Value="{StaticResource BackgroundBrush}" />
        <Setter Property="BorderBrush" Value="{StaticResource MiddleLightBrush}" />
        <Setter Property="BorderThickness" Value="{Binding RelativeSource={RelativeSource Self},Path=(params:General.DefaultThickness),Mode=OneWay}" />
        <Setter Property="Foreground" Value="{StaticResource ForegroundBrush}" />
        <Setter Property="FontSize" Value="{Binding RelativeSource={RelativeSource Self},Path=(params:General.ContentFontSize),Mode=OneWay}" />
        <Setter Property="FontStretch" Value="Medium" />
        <Setter Property="FontStyle" Value="Normal" />
        <Setter Property="FontWeight" Value="Normal" />
        <Setter Property="TextOptions.TextFormattingMode" Value="Display" />
        <Setter Property="TextOptions.TextRenderingMode" Value="ClearType" />
        <Setter Property="RenderOptions.ClearTypeHint" Value="Enabled" />
        <Setter Property="params:General.ShadowBrush" Value="{StaticResource ForegroundBrush}" />
        <Setter Property="Focusable" Value="True" />
        <Setter Property="FocusVisualStyle" Value="{StaticResource {x:Static SystemParameters.FocusVisualStyleKey}}"/>
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto" />
        <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" />
        <Setter Property="ScrollViewer.CanContentScroll" Value="True" />
        <Setter Property="ScrollViewer.PanningMode" Value="Both" />
        <Setter Property="Stylus.IsFlicksEnabled" Value="False" />
        <Setter Property="HorizontalContentAlignment" Value="Left" />
        <Setter Property="VerticalContentAlignment" Value="Center" />
        <Setter Property="Padding" Value="{Binding RelativeSource={RelativeSource Self}, Path=(params:General.SemiBoldPadding), Mode=OneWay}"/>
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ComboBox}">
                    <Decorator x:Name="LayoutRoot">
                        <controls:BorderFix Background="{TemplateBinding Background}" 
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="{Binding RelativeSource={RelativeSource TemplatedParent},Path=(params:ComboBox.ButtonSize),Converter={StaticResource DoubleToGridLengthConverter}}" />
                                </Grid.ColumnDefinitions>
                                <Popup x:Name="PART_Popup" Grid.Column="0" Grid.ColumnSpan="2" Popup.AllowsTransparency="True" Popup.Placement="Custom" 
                                       Popup.CustomPopupPlacementCallback="{x:Static params:DropDown.PopupPlacementCallback}" 
                                       Popup.PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" 
                                       FrameworkElement.Tag="{DynamicResource {x:Static SystemParameters.ComboBoxAnimationKey}}" 
                                       Popup.IsOpen="{Binding RelativeSource={RelativeSource TemplatedParent},Path=IsDropDownOpen,Mode=TwoWay}" 
                                       Popup.PlacementTarget="{Binding ElementName=LayoutRoot}" 
                                       Popup.VerticalOffset="{Binding RelativeSource={RelativeSource TemplatedParent},Path=BorderThickness,Converter={StaticResource ThicknessToDoubleConverter},ConverterParameter=Bottom}">
                                    <FrameworkElement.Resources>
                                        <ResourceDictionary>
                                            <Style TargetType="{x:Type ScrollBar}" BasedOn="{StaticResource {x:Type ScrollBar}}">
                                                <Style.Triggers>
                                                    <Trigger Property="ScrollBar.Orientation" Value="Vertical">
                                                        <Setter Property="BorderThickness" Value="0" />
                                                    </Trigger>
                                                </Style.Triggers>
                                            </Style>
                                        </ResourceDictionary>
                                    </FrameworkElement.Resources>
                                    <Border x:Name="PopupRoot" FrameworkElement.Tag="{DynamicResource {x:Static SystemParameters.DropShadowKey}}">
                                        <ScrollViewer x:Name="DropDownScrollViewer" 
                                                      Background="{StaticResource BackgroundBrush}" 
                                                      BorderBrush="{TemplateBinding BorderBrush}"
                                                      BorderThickness="{TemplateBinding BorderThickness}"
                                                      Foreground="{TemplateBinding Foreground}" 
                                                      FontSize="{TemplateBinding FontSize}" 
                                                      FontStretch="{TemplateBinding FontStretch}" 
                                                      FontStyle="{TemplateBinding FontStyle}" 
                                                      FontWeight="{TemplateBinding FontWeight}" 
                                                      TextOptions.TextFormattingMode="{TemplateBinding TextOptions.TextFormattingMode}" 
                                                      TextOptions.TextRenderingMode="{TemplateBinding TextOptions.TextRenderingMode}" 
                                                      RenderOptions.ClearTypeHint="{TemplateBinding RenderOptions.ClearTypeHint}" 
                                                      MaxHeight="{TemplateBinding ComboBox.MaxDropDownHeight}" 
                                                      MinWidth="{Binding ElementName=LayoutRoot,Path=ActualWidth}">
                                            <ItemsPresenter KeyboardNavigation.DirectionalNavigation="Contained"/>
                                        </ScrollViewer>
                                    </Border>
                                </Popup>
                                <ToggleButton x:Name="Button" Grid.Column="0" Grid.ColumnSpan="2" FrameworkElement.Style="{StaticResource ComboBoxToggleButton}" IsChecked="{Binding RelativeSource={RelativeSource TemplatedParent},Path=IsDropDownOpen,Mode=TwoWay}" />
                                <ContentPresenter x:Name="ContentPresenter" Grid.Column="0" ContentPresenter.Content="{TemplateBinding ComboBox.SelectionBoxItem}" ContentPresenter.ContentStringFormat="{TemplateBinding ComboBox.SelectionBoxItemStringFormat}" ContentPresenter.ContentTemplate="{TemplateBinding ComboBox.SelectionBoxItemTemplate}" ContentPresenter.ContentTemplateSelector="{TemplateBinding ItemsControl.ItemTemplateSelector}" TextBlock.Foreground="{TemplateBinding Foreground}" TextBlock.FontSize="{TemplateBinding FontSize}" TextBlock.FontStretch="{TemplateBinding FontStretch}" TextBlock.FontStyle="{TemplateBinding FontStyle}" TextBlock.FontWeight="{TemplateBinding FontWeight}" TextOptions.TextFormattingMode="{TemplateBinding TextOptions.TextFormattingMode}" TextOptions.TextRenderingMode="{TemplateBinding TextOptions.TextRenderingMode}" RenderOptions.ClearTypeHint="{TemplateBinding RenderOptions.ClearTypeHint}" UIElement.IsHitTestVisible="False" Margin="{TemplateBinding Padding}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Visibility="Visible" />
                                <Grid x:Name="TextBoxLayout" Grid.Column="0" Background="{TemplateBinding Background}" Visibility="Collapsed">
                                    <TextBox x:Name="PART_EditableTextBox" Foreground="{TemplateBinding Foreground}" Control.FontFamily="{TemplateBinding Control.FontFamily}" FontSize="{TemplateBinding FontSize}" FontStretch="{TemplateBinding FontStretch}" FontStyle="{TemplateBinding FontStyle}" FontWeight="{TemplateBinding FontWeight}" TextBoxBase.IsReadOnly="{TemplateBinding ComboBox.IsReadOnly}" Margin="{TemplateBinding Padding}" FrameworkElement.Style="{StaticResource ComboBoxTextBox}" />
                                </Grid>
                            </Grid>
                        </controls:BorderFix>
                    </Decorator>
                    <ControlTemplate.Triggers>
                        <Trigger Property="ComboBox.IsEditable" Value="True">
                            <Setter TargetName="Button" Property="Grid.Column" Value="1" />
                            <Setter TargetName="Button" Property="Grid.ColumnSpan" Value="1" />
                            <Setter TargetName="ContentPresenter" Property="Visibility" Value="Collapsed" />
                            <Setter TargetName="TextBoxLayout" Property="Visibility" Value="Visible" />
                        </Trigger>
                        <Trigger Trigger.SourceName="PART_Popup" Property="FrameworkElement.Tag" Value="False">
                            <Setter TargetName="PART_Popup" Property="Popup.PopupAnimation" Value="None" />
                        </Trigger>
                        <Trigger Property="ComboBox.IsDropDownOpen" Value="True">
                            <Setter TargetName="PART_Popup" Property="params:DropDown.IsOpen" Value="True" />
                        </Trigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Condition.SourceName="PART_Popup" Property="params:DropDown.IsDefaultHorizontalPosition" Value="True" />
                                <Condition Condition.SourceName="PART_Popup" Property="params:DropDown.IsDefaultVerticalPosition" Value="True" />
                            </MultiTrigger.Conditions>
                            <MultiTrigger.Setters>
                                <Setter TargetName="DropDownScrollViewer" Value="{Binding RelativeSource={RelativeSource TemplatedParent},Path=BorderThickness,Mode=OneWay,Converter={StaticResource ThicknessConverter},ConverterParameter='Left, Right, Bottom'}" Property="BorderThickness" />
                            </MultiTrigger.Setters>
                        </MultiTrigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Condition.SourceName="PART_Popup" Property="params:DropDown.IsDefaultHorizontalPosition" Value="True" />
                                <Condition Condition.SourceName="PART_Popup" Property="params:DropDown.IsDefaultVerticalPosition" Value="False" />
                            </MultiTrigger.Conditions>
                            <MultiTrigger.Setters>
                                <Setter TargetName="DropDownScrollViewer" Value="{Binding RelativeSource={RelativeSource TemplatedParent},Path=BorderThickness,Mode=OneWay,Converter={StaticResource ThicknessConverter},ConverterParameter='Left, Top, Right'}" Property="BorderThickness" />
                            </MultiTrigger.Setters>
                        </MultiTrigger>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Condition.Binding="{Binding ElementName=PopupRoot,Path=Tag}" Value="True" />
                                <Condition Condition.Binding="{Binding ElementName=PART_Popup,Path=(params:DropDown.IsDefaultVerticalPosition)}" Value="True" />
                            </MultiDataTrigger.Conditions>
                            <MultiDataTrigger.Setters>
                                <Setter TargetName="PopupRoot" Property="UIElement.Effect">
                                    <Setter.Value>
                                        <DropShadowEffect DropShadowEffect.BlurRadius="4" DropShadowEffect.ShadowDepth="2" DropShadowEffect.Direction="315" DropShadowEffect.Opacity="0.3" DropShadowEffect.Color="{Binding RelativeSource={RelativeSource AncestorType={x:Type ComboBox}},Path=(params:General.ShadowBrush).(SolidColorBrush.Color)}" />
                                    </Setter.Value>
                                </Setter>
                                <Setter TargetName="PopupRoot" Value="{StaticResource TransparentBrush}" Property="Border.Background" />
                                <Setter TargetName="PopupRoot" Property="Border.Padding" Value="0,0,6,6" />
                            </MultiDataTrigger.Setters>
                        </MultiDataTrigger>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Condition.Binding="{Binding ElementName=PopupRoot,Path=Tag}" Value="True" />
                                <Condition Condition.Binding="{Binding ElementName=PART_Popup,Path=(params:DropDown.IsDefaultVerticalPosition)}" Value="False" />
                            </MultiDataTrigger.Conditions>
                            <MultiDataTrigger.Setters>
                                <Setter TargetName="PopupRoot" Property="UIElement.Effect">
                                    <Setter.Value>
                                        <DropShadowEffect DropShadowEffect.BlurRadius="4" DropShadowEffect.ShadowDepth="0" DropShadowEffect.Direction="45" DropShadowEffect.Opacity="0.3" DropShadowEffect.Color="{Binding RelativeSource={RelativeSource AncestorType={x:Type ComboBox}},Path=(params:General.ShadowBrush).(SolidColorBrush.Color)}" />
                                    </Setter.Value>
                                </Setter>
                                <Setter TargetName="PopupRoot" Value="{StaticResource TransparentBrush}" Property="Border.Background" />
                                <Setter TargetName="PopupRoot" Property="Border.Padding" Value="0,4,4,0" />
                            </MultiDataTrigger.Setters>
                        </MultiDataTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <DataTrigger DataTrigger.Binding="{Binding RelativeSource={RelativeSource Self},Path=FontSize,Mode=OneWay,Converter={StaticResource IsGreaterThanConverter},ConverterParameter=18}">
                <Setter Property="TextOptions.TextFormattingMode" Value="Ideal" />
            </DataTrigger>
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="BorderBrush" Value="{StaticResource DisabledBrush}" />
                <Setter Property="Foreground" Value="{StaticResource DisabledBrush}" />
            </Trigger>
            <Trigger Property="ItemsControl.IsGrouping" Value="True">
                <Setter Property="ScrollViewer.CanContentScroll" Value="False" />
            </Trigger>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="Background" Value="{StaticResource HighlightBrush}" />
                <Setter Property="BorderBrush" Value="{StaticResource AccentBrush}" />
            </Trigger>
            <Trigger Property="ComboBox.IsDropDownOpen" Value="True">
                <Setter Property="Background" Value="{StaticResource HighlightBrush}" />
            </Trigger>
        </Style.Triggers>
    </Style>
    
    <Style x:Key="TransparentComboBoxStyle" BasedOn="{StaticResource {x:Type ComboBox}}" TargetType="{x:Type ComboBox}">
        <Setter Property="Background" Value="{StaticResource TransparentBrush}"/>
        <Setter Property="BorderThickness" Value="0"/>
    </Style>
    
</ResourceDictionary>